using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using RulesEngine;

namespace Polymod.TemplateBuilders
{
    public class ValidationModelTemplateBuilder : FormulaModelTemplateBuilder
    {
        Engine _rulesEngine;

        public ValidationModelTemplateBuilder(Engine rulesEngine)
        {
            if (rulesEngine == null) throw new System.ArgumentNullException("rulesEngine");
            _rulesEngine = rulesEngine;
        }

        protected override IDictionary<string, object> CreateModelTemplateState(ModelTemplateParameters parameters)
        {
            var result = base.CreateModelTemplateState(parameters);
            result.Add(Constants.RulesEngine, _rulesEngine);
            return result;
        }

        protected override Type GetModelBaseType(ModelTemplateParameters parameters)
        {
            return typeof(ValidationModel<>).MakeGenericType(parameters.ModelType);
        }
    }
}
